package com.lcf.system.controller;

import com.lcf.framework.annotation.PermissionCheck;
import com.lcf.framework.vo.PageVO;
import com.lcf.system.dto.dict.SysDictDTO;
import com.lcf.system.dto.dict.SysDictStatusDTO;
import com.lcf.system.query.dict.SysDictPageQuery;
import com.lcf.system.service.SysDictService;
import com.lcf.system.vo.dict.SysDictDetailVO;
import com.lcf.system.vo.dict.SysDictVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.lcf.framework.enums.PermissionEnum.*;

/**
 * 字典值(SysDict)表控制层
 *
 * @author lcf
 * @since 2025-03-16 22:04:23
 */
@Tag(name = "字典值")
@RestController
@RequestMapping("sysDict")
public class SysDictController {
    @Resource
    private SysDictService sysDictService;

    /**
     * 新增字典
     */
    @Operation(summary = "新增字典")
    @PermissionCheck(SYS_DICT_ADD)
    @PostMapping
    public void add(@RequestBody @Validated SysDictDTO dto) {
        sysDictService.add(dto);
    }
    /**
     * 修改字典
     */
    @Operation(summary = "修改字典")
    @PermissionCheck(SYS_DICT_EDIT)
    @PatchMapping("{dictId}")
    public void edit(@PathVariable @Schema(description = "字典ID") long dictId,
                     @RequestBody @Validated SysDictDTO dto) {
        sysDictService.edit(dictId, dto);
    }
    /**
     * 删除字典
     */
    @Operation(summary = "删除字典")
    @PermissionCheck(SYS_DICT_DEL)
    @DeleteMapping("{dictId}")
    public void delete(@PathVariable @Schema(description = "字典ID") long dictId) {
        sysDictService.delete(dictId);
    }
    /**
     * 批量删除字典
     */
    @Operation(summary = "批量删除字典")
    @PermissionCheck(SYS_DICT_DEL)
    @DeleteMapping("list")
    public void delete(@RequestBody @Schema(description = "字典ID") List<Long> ids) {
        sysDictService.delete(ids);
    }
    /**
     * 字典停启用
     */
    @Operation(summary = "字典停启用")
    @PermissionCheck(SYS_DICT_EDIT_STATUS)
    @PatchMapping("status")
    public void changeStatus(@RequestBody @Validated SysDictStatusDTO dto) {
        sysDictService.changeStatus(dto);
    }
    /**
     * 字典详情
     */
    @Operation(summary = "字典详情")
    @PermissionCheck(SYS_DICT_DETAIL)
    @GetMapping("{dictId}")
    public SysDictDetailVO get(@PathVariable @Schema(description = "字典ID") long dictId) {
        return sysDictService.get(dictId);
    }
    /**
     * 字典分页
     */
    @Operation(summary = "字典分页")
    @PermissionCheck(SYS_DICT_PAGE)
    @GetMapping("page")
    public PageVO<SysDictVO> page(@Validated SysDictPageQuery query) {
        return sysDictService.page(query);
    }
}

